package se.tinkerway.bomberman.controller;

import se.tinkerway.bomberman.domain.Bomberman;
import se.tinkerway.bomberman.domain.Position;
import se.tinkerway.bomberman.view.KeyboardInterface;

public class KeyboardController implements BombermanController {
	private Bomberman bomberman;
	
	private KeyboardInterface keyboard;
	
	public KeyboardController(Bomberman bomberman, KeyboardInterface keyboard) {
		this.bomberman = bomberman;
		this.keyboard = keyboard;
	}
	
	@Override
	public void perform() {
		Position delta = new Position(0, 0);
		
		if (keyboard.isKeyPressed(KeyboardInterface.KEY_CODE.UP)) {
			delta = new Position(0, -1);
		}
		
		if (keyboard.isKeyPressed(KeyboardInterface.KEY_CODE.DOWN)) {
			delta = new Position(0, 1);
		}
		
		if (keyboard.isKeyPressed(KeyboardInterface.KEY_CODE.LEFT)) {
			delta = new Position(-1, 0);
		}
		
		if (keyboard.isKeyPressed(KeyboardInterface.KEY_CODE.RIGHT)) {
			delta = new Position(1, 0);
		}
		
		bomberman.move(delta);
		
		if (keyboard.isKeyPressed(KeyboardInterface.KEY_CODE.BOMB)) {
			bomberman.dropBomb();
		}
	}

}
